<?php
/**
 * Base_App
 *
 * LICENSE
 *
 * This source file is subject to the new CC-GNU LGPL
 * It is available through the world-wide-web at this URL:
 * http://creativecommons.org/licenses/LGPL/2.1/
 *
 * @category   Base_App
 * @copyright  Copyright (c) 2009 Alexander fanatique* Thomas (me@alexander-thomas.net)
 * @license    http://creativecommons.org/licenses/LGPL/2.1/
 */

ini_set('memory_limit', '24M');

/** Determine the environment and the include paths*/

$dirname = dirname(__FILE__) . '/';

$pathInclude = $dirname . '../library/';
$pathApplication = $dirname . '../application/';

set_include_path(get_include_path() . PATH_SEPARATOR . $pathInclude . PATH_SEPARATOR . $pathApplication);

//Set up Zend Loader (ZF 1.8)
require_once 'Zend/Loader/Autoloader/Resource.php';
require_once 'Zend/Loader/Autoloader.php';

$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
    'basePath'  => $dirname.'../',
    'namespace' => '',
));
$resourceLoader	->addResourceType('base', 'library/Base/', 'Base')
               	->addResourceType('service', 'application/Service/', 'Service')
               	->addResourceType('Model', 'application/Model/', 'Model')
               	->addResourceType('exception', 'application/Exception/', 'Exception')
				->addResourceType('zend', 'library/Zend/', 'Zend');

//Initialization of the Base App
$app = Base_App_Web::getInstance();
try{
	$app->init($pathApplication);	
}catch(Base_App_Initialization_Exception $e){
	//Something within the intialization phase went wrong
	Base_App_Debug::dd($e);
}catch(Exception $e){
	//Something else went wrong
	Base_App_Debug::dd($e);
}

//Run
try{
	Zend_Layout::startMvc(array('layoutPath' => $pathApplication . 'Layouts'));
	$app->run();
}catch(Base_App_Acl_Exception $e){
	//Do stuff when someone tried to enter as ressource he has no privileges for.
	header('Location: /error/FAILURE_ACL_NO_ACCESS');	
}catch(Zend_Controller_Dispatcher_Exception $e){
	//Do stuff when something with the MVC workflow crashed.
	header('Location: /error/FAILURE_DISPATCH');
}catch(Exception $e){
	//Do stuff when something happened.
	Base_App_Debug::dd($e);
	header('Location: /error/GENERAL');
}
?>
